package com.jollychic.www.roomdatebasedemo.convert;

import android.arch.persistence.room.TypeConverter;
import android.text.TextUtils;

import com.alibaba.fastjson.TypeReference;
import com.jollychic.www.roomdatebasedemo.model.ComputerEntity;
import com.jollychic.www.roomdatebasedemo.tool.ToolJson;

import java.lang.reflect.Type;
import java.util.List;

/**
 * desc:  <br/>
 * author: 李超杰 <br/>
 * date: 2018/5/9 下午1:01 <br/>
 * since v <br/>
 */
public class Converts {

    /**
     * 店铺-computerEntity
     */
    public static final Type STORE_COMPUTER_TYPE = new TypeReference<List<ComputerEntity>>() {
    }.getType();

    @TypeConverter
    public static List<ComputerEntity> fromComputerEntityListString(String value) {
        return TextUtils.isEmpty(value) ? null : (List<ComputerEntity>) ToolJson
                .transform2Object(value, STORE_COMPUTER_TYPE);
    }

    @TypeConverter
    public static String computerEntityList2Json(List<ComputerEntity> list) {
        return ToolJson.transform2JsonString(list);
    }
}
